package com.jmb.api.web.controller.project;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmb.api.common.result.Result;
import com.jmb.api.entity.Project;
import com.jmb.api.vo.project.ProjectInfoVO;
import com.jmb.api.vo.project.ProjectModuleNameVO;
import com.jmb.api.vo.project.ProjectQueryVO;
import com.jmb.api.vo.project.ProjectVO;
import com.jmb.api.web.service.ProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "项目管理")
@RestController
@RequestMapping("/web/project")
public class ProjectController {
    @Autowired
    private ProjectService projectService;
    // 新增更新项目
    @Operation(summary = "新增更新项目")
    @PostMapping("/saveOrUpdateProject")
    public Result saveOrUpdateProject(@RequestBody  @Valid Project project){
        projectService.saveOrUpdateProject(project);
        return Result.ok();
    }


    // 查询项目
    @Operation(summary = "查询项目")
    @GetMapping("/getProject")
    public Result<Project> getProject(@RequestParam Long id){
        Project project = projectService.getById(id);
        return Result.ok(project);
    }
    // 项目列表
    @Operation(summary = "项目列表")
    @GetMapping("/getProjectList")
    public Result<IPage<ProjectInfoVO>> getProjectList( ProjectQueryVO projectQueryVO){
        IPage<ProjectInfoVO> page = new Page<>(projectQueryVO.getPageNum(), projectQueryVO.getPageSize());
        IPage<ProjectInfoVO> list = projectService.listProjectInfo(page, projectQueryVO);
        return Result.ok(list);
    }

    // 删除项目
    @Operation(summary = "删除项目")
    @DeleteMapping("/deleteProject")
    public Result  deleteProject(@RequestParam Long id){
        projectService.removeById(id);
        return Result.ok();
    }

    // 查询项目名称供模块管理使用
    @Operation(summary = "查询项目名称")
    @GetMapping("/getProjectName")
    public Result<List<ProjectModuleNameVO>> getProjectName(){
        List<ProjectModuleNameVO> projectName = projectService.getProjectName();
        return Result.ok(projectName);
    }

}
